package com.xungou.user.service.impl;  
  
import java.util.Map;

import javax.annotation.Resource;

import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.springframework.stereotype.Service;

import com.xungou.user.dao.IUserDao;
import com.xungou.user.pojo.User;
import com.xungou.user.service.IUserService;
import com.xungou.utils.SecurityUtil;  
  

  
@Service("userService")  
public class UserServiceImpl implements IUserService {  
    @Resource  
    private IUserDao userDao;  
    public User getUserById(int userId) {  
        return this.userDao.selectByPrimaryKey(userId);
    }
	public int register(User user) {
		String salt = SecurityUtil.getRandomStr();
		String psw = SecurityUtil.encodeByMD5(user.getPassword());
		user.setPassword(psw);
		return userDao.insert(user); 
	}
	public int isRepeat(Map<String, String> params) {
		User user = userDao.isRepeat(params);
		if(user!=null)
			return 1;
		else
			return 0;
	}

	@Override
	public User getUserByName(String name) {
		return userDao.getUserByName(name);
	}
}